package com.yimi.yinhepda.entity.response;

import com.yimi.yinhepda.utils.Common;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/12 0012
 * <p>
 * 盘点扫描的返回结果
 */

public class CheckScanTaskResponse implements Serializable {

    public boolean success;
    private String[] errorMessages;
    private int errorCode;
    public List<CheckScanEntity> data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String[] getErrorMessages() {
        return errorMessages;
    }

    public void setErrorMessages(String[] errorMessages) {
        this.errorMessages = errorMessages;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public List<CheckScanEntity> getData() {
        return data;
    }

    public void setData(List<CheckScanEntity> data) {
        this.data = data;
    }

    /**
     * 库存票数
     */
    public static int getStockTicket(List<CheckScanEntity> data) {
        return data.size();
    }

    /**
     * 库存件数
     */
    public static int getStockPieces(List<CheckScanEntity> data) {
        int count = 0;
        for (CheckScanEntity item : data) {
            count += item.getInventoryNum();
        }
        return count;
    }

    /**
     * 已扫描票数
     */
    public static int getTotalScannedTicket(List<CheckScanEntity> data) {
        int count = 0;
        List<ChildInfo> childList;
        for (CheckScanEntity item : data) {
            childList = item.getStocktakingDiffreportInventoryList();
            if (childList == null) {
                return count;
            }
            for (ChildInfo childItem : childList) {
                if (childItem.getStockStatus() == 1) {
                    count++;
                    break;//加一次就好，退出当前for循环，继续
                }
            }
        }
        return count;
    }

    /**
     * 已扫描件数
     */
    public static int getTotalScannedPiece(List<CheckScanEntity> data) {
        int count = 0;
        for (CheckScanEntity item : data) {
            count += item.getScannedNum();
        }
        return count;
    }

    /**
     * 总的实重量
     */
    public static double getTotalRealWeight(List<CheckScanTaskResponse.CheckScanEntity> list) {
        double totalWeight = 0.0;
        for (CheckScanTaskResponse.CheckScanEntity item : list) {
            totalWeight += item.getRealWeight().doubleValue();
        }
        return totalWeight;
    }

    /**
     * 总的计费重量
     */
    public static double getTotalChargeableWeight(List<CheckScanTaskResponse.CheckScanEntity> list) {
        double totalWeight = 0.0;
        for (CheckScanTaskResponse.CheckScanEntity item : list) {
            totalWeight += item.getChargeableWeight().doubleValue();
        }
        return totalWeight;
    }

    /**
     * 总的体积
     */
    public static double getTotalVolume(List<CheckScanTaskResponse.CheckScanEntity> list) {
        double totalVolume = 0.0;
        for (CheckScanTaskResponse.CheckScanEntity item : list) {
            totalVolume += item.getVolume().doubleValue();
        }
        return totalVolume;
    }

    public static class CheckScanEntity implements Comparable<CheckScanEntity>, Serializable {
        /**
         * 主单号
         */
        private String waybillNo;
        /**
         * 开单件数
         */
        private Integer quantity;
        /**
         * 库存件数
         */
        private Integer inventoryNum;
        /**
         * 包装
         */
        private String packingSpecification;
        /**
         * 体积
         */
        private BigDecimal volume;
        /**
         * 计费重量
         */
        private BigDecimal chargeableWeight;
        /**
         * 实重
         */
        private BigDecimal realWeight;
        /**
         * 强扫
         */
        private String remark;
        /**
         * 产品类型（1：定日达2：次日达3：次晨达4：标准快运）
         */
        private String productTypeSelect;
        /**
         * 必走货状态1：必走货2：串货3：标准货
         */
        private String effectiveType;
        /**
         * 二级排序： 时>比>优>串>标
         */
        private int secondSort = Common.GOODSP_RIORITY_DEFAULT;
        /**
         * 运单子单集合
         */
        private List<ChildInfo> stocktakingDiffreportInventoryList;

        public int getSecondSort() {
            return secondSort;
        }

        public void setSecondSort(int secondSort) {
            this.secondSort = secondSort;
        }

        public String getProductTypeSelect() {
            return productTypeSelect;
        }

        public void setProductTypeSelect(String productTypeSelect) {
            this.productTypeSelect = productTypeSelect;
        }

        public String getEffectiveType() {
            return effectiveType;
        }

        public void setEffectiveType(String effectiveType) {
            this.effectiveType = effectiveType;
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }

        public String getWaybillNo() {
            return waybillNo;
        }

        public void setWaybillNo(String waybillNo) {
            this.waybillNo = waybillNo;
        }

        public Integer getQuantity() {
            if (quantity == null) {
                return 0;
            }
            return quantity;
        }

        public void setQuantity(Integer quantity) {
            this.quantity = quantity;
        }

        public Integer getInventoryNum() {
            if (inventoryNum == null) {
                return 0;
            }
            return inventoryNum;
        }

        public void setInventoryNum(Integer inventoryNum) {
            this.inventoryNum = inventoryNum;
        }

        public String getPackingSpecification() {
            return packingSpecification;
        }

        public void setPackingSpecification(String packingSpecification) {
            this.packingSpecification = packingSpecification;
        }

        public BigDecimal getVolume() {
            if (volume == null) {
                volume = BigDecimal.ZERO;
            }
            return volume;
        }

        public void setVolume(BigDecimal volume) {
            this.volume = volume;
        }

        public BigDecimal getChargeableWeight() {
            if (chargeableWeight == null) {
                chargeableWeight = BigDecimal.ZERO;
            }
            return chargeableWeight;
        }

        public void setChargeableWeight(BigDecimal chargeableWeight) {
            this.chargeableWeight = chargeableWeight;
        }

        public BigDecimal getRealWeight() {
            if (realWeight == null) {
                realWeight = BigDecimal.ZERO;
            }
            return realWeight;
        }

        public void setRealWeight(BigDecimal realWeight) {
            this.realWeight = realWeight;
        }

        public List<ChildInfo> getStocktakingDiffreportInventoryList() {
            return stocktakingDiffreportInventoryList;
        }

        public void setStocktakingDiffreportInventoryList(List<ChildInfo> stocktakingDiffreportInventoryList) {
            this.stocktakingDiffreportInventoryList = stocktakingDiffreportInventoryList;
        }

        /**
         * 获取已经扫描的子单数量
         */
        public int getScannedNum() {
            int count = 0;
            if (stocktakingDiffreportInventoryList == null) {
                return count;
            }
            for (ChildInfo childInfo : stocktakingDiffreportInventoryList) {
                if (childInfo.getStockStatus() != null && childInfo.getStockStatus() == 1) {
                    count++;
                }
            }
            return count;
        }

        /**
         * 对颜色的判断
         */
        public int justColorShow() {
            //库存数量
            int srcPiecesNum = getInventoryNum();
            //扫描数量
            int scannedNum = getScannedNum();
            if (scannedNum == 0) {
                //白色
                return 1;
            } else if (scannedNum < srcPiecesNum) {
                //红色
                return 0;
            }
            if (scannedNum > srcPiecesNum) {
                //黄色
                return 2;
            } else {
                //绿色
                return 3;
            }
        }

        @Override
        public int compareTo(CheckScanEntity checkScanEntity) {
            return this.justColorShow() - checkScanEntity.justColorShow();
        }
    }

    /**
     * 子单信息集合
     */
    public static class ChildInfo implements Serializable {
        /**
         * 子单号或者包号
         */
        private String waybillChildNo;
        /**
         * 0是未扫描，1是已扫描
         */
        private Integer stockStatus;
        /**
         * 是否已打印：2或者空-已打印，1-未打印（需要打印标签）
         */
        private Integer bePrint;
        /**
         * 滞留原因
         */
        private String column1;

        public String getColumn1() {
            return column1;
        }

        public void setColumn1(String column1) {
            this.column1 = column1;
        }

        public String getWaybillChildNo() {
            return waybillChildNo;
        }

        public void setWaybillChildNo(String waybillChildNo) {
            this.waybillChildNo = waybillChildNo;
        }

        public Integer getStockStatus() {
            return stockStatus;
        }

        public void setStockStatus(Integer stockStatus) {
            this.stockStatus = stockStatus;
        }

        public Integer getBePrint() {
            return bePrint;
        }

        public void setBePrint(Integer bePrint) {
            this.bePrint = bePrint;
        }
    }
}
